package com.geektime.hello.common;

import lombok.Data;

/**
 * @Author: DRevelation
 * @Date: 2020/12/28 15:33
 */
@Data
public class Result {

    private Integer code;
    private String msg;
    private Object data;

    public Result() {}

    public Result(ResultCode resultCode, Object data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public static Result success() {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMsg());
        return result;
    }

    public static Result success(Object data) {
        return new Result(ResultCode.SUCCESS, data);
    }

    public static Result fail(Object data) {
        return new Result(ResultCode.FAILURE, data);
    }

    public static void main(String[] args) {
        Result r1 = Result.success();
        Result r2 = Result.success("哈哈");
        Result r3 = Result.fail("呜呜");
        System.out.println("r1 = " + r1);
        System.out.println("r2 = " + r2);
        System.out.println("r3 = " + r3);

    }
}
